#ifndef __DFS_FS_H_
#define __DFS_FS_H_

#ifdef __cplusplus
extern "C"
{
#endif

#include "./dfs.h"
#include "./dfs_file.h"

/* Pre-declaration */
struct dfs_filesystem;
struct dfs_fd;

struct statfs
{
    size_t f_bsize;   /* block size */
    size_t f_blocks;  /* total data blocks in file system */
    size_t f_bfree;   /* free blocks in file system */
};

/* File system operations */
struct dfs_filesystem_ops
{
    char *name;
    uint32_t flags;      /* flags for file system operations */

    /* operations for file */
    const struct dfs_file_ops *fops;

    /* mount and unmount file system */
    int (*mount)    (struct dfs_filesystem *fs, unsigned long rwflag, const void *data);
    int (*unmount)  (struct dfs_filesystem *fs);

    /* make a file system */
    int (*mkfs)     (const char *dev_name);
    int (*statfs)   (struct dfs_filesystem *fs, struct statfs *buf);

    int (*unlink)   (struct dfs_filesystem *fs, const char *pathname);
    int (*stat)     (struct dfs_filesystem *fs, const char *filename, struct stat *buf);
    int (*rename)   (struct dfs_filesystem *fs, const char *oldpath, const char *newpath);
};

/* Mounted file system */
struct dfs_filesystem
{
    // rt_device_t dev_id;     /* Attached device */
    const char *dev_name;   /* Attached device name */

    char *path;             /* File system mount point */
    const struct dfs_filesystem_ops *ops; /* Operations for file system type */

    void *data;             /* Specific file system data */
};

/* file system partition table */
struct dfs_partition
{
    uint8_t type;        /* file system type */
    off_t  offset;       /* partition start offset */
    size_t size;         /* partition size */
    void *mutex;
};

/* mount table */
struct dfs_mount_tbl
{
    const char   *device_name;
    const char   *path;
    const char   *filesystemtype;
    unsigned long rwflag;
    const void   *data;
};


/* export func */

int dfs_fs_register(const struct dfs_filesystem_ops *ops);
struct dfs_filesystem *dfs_fs_lookup(const char *path);
// const char *dfs_fs_get_mounted_path(void *obj);
// int dfs_fs_get_partition(void *obj);
int dfs_fs_mount(const char *dev_name, const char *path, const char *fs_type, uint32_t rwflag, const void *data);
int dfs_fs_unmount(const char *path);
int dfs_fs_mkfs(const char *fs_name, const char *dev_name);
int dfs_fs_statfs(const char *path, struct statfs *buffer);


#ifdef __cplusplus
}
#endif

#endif // __DFS_FS_H_
